package com.example.shop_2304

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.base.mvvm.BaseViewActivity
import com.example.shop_2304.adapter.MyTabEntity
import com.example.shop_2304.adapter.VpAdapter
import com.example.shop_2304.databinding.ActivityWelBinding
import com.example.shop_2304.welfg.BlankFragment
import com.example.shop_2304.welfg.BlankFragment2
import com.example.shop_2304.welfg.BlankFragment3
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener

/**
 * 引导页：当点击立即进入（倒计时结束）时 ，判断用户是否登录，如果已经登录，跳转到主页页面，如果未登录，跳转到登录界面
 */
class WelActivity : BaseViewActivity<ActivityWelBinding>() {
    lateinit var vpAdapter: VpAdapter
    var list = mutableListOf<Fragment>()
    var tabs = ArrayList<CustomTabEntity>()
    override fun initView() {
        list.add(BlankFragment())
        list.add(BlankFragment2())
        list.add(BlankFragment3())
        vpAdapter = VpAdapter(this,list)
        binding.vp.adapter = vpAdapter

        tabs.add(MyTabEntity("",R.drawable.baseline_remove_24,R.drawable.baseline_circle_24))
        tabs.add(MyTabEntity("",R.drawable.baseline_remove_24,R.drawable.baseline_circle_24))
        tabs.add(MyTabEntity("",R.drawable.baseline_remove_24,R.drawable.baseline_circle_24))
        binding.tab.setTabData(tabs)

        //相互滑动，相互影响
        binding.vp.registerOnPageChangeCallback(object:ViewPager2.OnPageChangeCallback(){
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.tab.currentTab = position
            }

        })
        binding.tab.setOnTabSelectListener(object:OnTabSelectListener{
            override fun onTabSelect(position: Int) {
                binding.vp.currentItem = position
            }

            override fun onTabReselect(position: Int) {

            }
        })
        //因时间有限，用1分钟来模拟效果
        //获取上次离开时间  //小于1分钟，不展示引导页   大于1分钟 展示引导页
        val long = SPUtils.getInstance().getLong("time")
        if(System.currentTimeMillis()-long<60*1000){
            ARouter.getInstance().build("/app/MainActivity").navigation(this,object :
                NavigationCallback {
                override fun onFound(postcard: Postcard?) {
                    //找到
                }

                override fun onLost(postcard: Postcard?) {
                    //迷失   找不到对应路径
                }

                override fun onArrival(postcard: Postcard?) {
                    //到达   跳转到指定页面
                    finish()
                }

                override fun onInterrupt(postcard: Postcard?) {
                    //拦截
                }
            })

        }
    }

    override fun initData() {

    }

    override fun getLayout(): Int  = R.layout.activity_wel

}